package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MTeacher;
import com.ruoyi.system.service.IMTeacherService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 老师个人资料Controller
 * 
 * @author ZHANGQIBO
 * @date 2023-12-25
 */
@RestController
@RequestMapping("/system/teacher")
public class MTeacherController extends BaseController
{
    @Autowired
    private IMTeacherService mTeacherService;

    /**
     * 查询老师个人资料列表
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:list')")
    @GetMapping("/list")
    public TableDataInfo list(MTeacher mTeacher)
    {
        startPage();
        List<MTeacher> list = mTeacherService.selectMTeacherList(mTeacher);
        return getDataTable(list);
    }

    /**
     * 查询老师个人资料列表
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:list')")
    @GetMapping("/Teacherlist")
    public AjaxResult Teacherlist(String coursename)
    {
        List<MTeacher> list = mTeacherService.selectCourseMTeacherList(coursename);
        return AjaxResult.success(list);
    }

    /**
     * 导出老师个人资料列表
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:export')")
    @Log(title = "老师个人资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MTeacher mTeacher)
    {
        List<MTeacher> list = mTeacherService.selectMTeacherList(mTeacher);
        ExcelUtil<MTeacher> util = new ExcelUtil<MTeacher>(MTeacher.class);
        util.exportExcel(response, list, "老师个人资料数据");
    }

    /**
     * 获取老师个人资料详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mTeacherService.selectMTeacherById(id));
    }

    /**
     * 新增老师个人资料
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:add')")
    @Log(title = "老师个人资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MTeacher mTeacher)
    {
        return toAjax(mTeacherService.insertMTeacher(mTeacher));
    }

    /**
     * 修改老师个人资料
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:edit')")
    @Log(title = "老师个人资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MTeacher mTeacher)
    {
        return toAjax(mTeacherService.updateMTeacher(mTeacher));
    }

    /**
     * 删除老师个人资料
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:remove')")
    @Log(title = "老师个人资料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mTeacherService.deleteMTeacherByIds(ids));
    }
}
